<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2023-07-28 14:38:50
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Models;

use App\Traits\SoftDeletesTrait;
use App\Traits\AttachmentTrait;
use App\Traits\AutoCodeTrait;
use App\Traits\VoucherTrait;

class MarketOrder extends BaseModel
    {
    use SoftDeletesTrait;
    use AutoCodeTrait;
    use AttachmentTrait;
    use VoucherTrait;
    public $timestamps = true;
    public $table = "sys_market_order";
    protected $guarded = [];
    //附件
    public $attachmentkey = "code";

    protected $casts = [
        'tax'               => 'decimal:2',
        'amount'            => 'decimal:2',
        'tax_amount'        => 'decimal:2',
        'rate'              => 'decimal:2',
        'quantity'          => 'decimal:2',
        'feeding_ratio'     => 'decimal:2',
        'price'             => 'decimal:2',
        'tax_price'         => 'decimal:2',
        'delivery_quantity' => 'decimal:2',
        'pro_quantity'      => 'decimal:2',
    ];


    /**
     * 标识
     *
     * @var string
     */
    protected $ACSign = 'MARKET_ORDER';

    /**
     * 编号所用的字段
     *
     * @var string
     */
    protected $ACCode = 'code';

    public function status()
        {
        return $this->belongsTo(Dic::class, "status_id", "key")->where(function ($q)
            {
            $q->where("code", 'OrderStatus');
            });
        }
    public function customer()
        {
        return $this->belongsTo(Company::class);
        }
    public function details()
        {
        return $this->hasMany(MarketOrderDetails::class, "main_id");
        }

    public function linkman()
        {
        return $this->belongsTo(CompanyLinkMan::class);
        }
    public function process_route()
        {
        return $this->belongsTo(ProProcessRoute::class);
        }
    public function process()
        {
        return $this->belongsTo(ProProcesses::class);
        }
    public function department()
        {
        return $this->belongsTo(Department::class);
        }
    }
